package com.future.interview;

/**
 * Description:
 *
 * @Author: future
 * @Date:2022/3/3:23:11
 */
public class Test {

    public static void main(String[] args) {
        int[][] nums = {
                {1, 0, 0, 1},
                {1, 1, 0, 1},
                {0, 1, 0,0},
        };
        int ans = 0;
        int n = nums.length;
        int m = nums[0].length;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (nums[i][j] == 1) {
                    ans = Math.max(ans, process(nums, i, j));
                }
            }
        }
        System.out.println(ans);
    }

    private static int process(int[][] nums, int i, int j) {
        if (i < 0 || i >= nums.length || j < 0 || j >= nums[0].length) {
            return 0;
        }
        int val = nums[i][j];
        if (val == 0) {
            return 0;
        }
        return 1 + process(nums, i - 1, j) +
                process(nums, i + 1, j) +
                process(nums, i, j - 1) +
                process(nums, i, j + 1);
    }


}
